class Utils {
  private getNumericStyleProperty = (style, prop) => {
    return parseInt(style.getPropertyValue(prop), 10);
  };
  /**
   ** 获取元素距离window的left,top值
   ** return {x:number, y:number}
   * **/
  public element_position = (e) => {
    var x = 0,
      y = 0;
    var inner = true;
    do {
      x += e.offsetLeft;
      y += e.offsetTop;
      var style = getComputedStyle(e, null);
      var borderTop = this.getNumericStyleProperty(style, 'border-top-width');
      var borderLeft = this.getNumericStyleProperty(style, 'border-left-width');
      y += borderTop;
      x += borderLeft;
      if (inner) {
        var paddingTop = this.getNumericStyleProperty(style, 'padding-top');
        var paddingLeft = this.getNumericStyleProperty(style, 'padding-left');
        y += paddingTop;
        x += paddingLeft;
      }
      inner = false;
    } while ((e = e.offsetParent));
    return { x: x, y: y };
  };
}

const urils = new Utils();
export default urils;
